import {  Injector } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { INameValue } from '@shared/service-proxies/service-proxies';
import { forEach as _forEach } from 'lodash-es';
import { LayoutStyles } from './layout-content-style';
import { LayoutContentType } from './layout-element';

export class editStyleBaseComponent extends AppComponentBase{
    
    PaddingMoreOptions: boolean = false;
    MarginMoreOptions: boolean = false;
    BorderMoreOptions: boolean = false;
    BorderRadiusMoreOptions: boolean = false;

    data: LayoutStyles;
    type:LayoutContentType

    borderStyle: INameValue[] =[
        { name:'实线边框',value:'solid'},
        { name:'虚线边框',value:'dashed'},
        { name:'点状边框',value:'dotted'},
        { name:'双线边框',value:'double'},
        { name:'凹槽边框',value:'groove'},
        { name:'垄状边框',value:'ridge'},
        { name:'3D inset 边框',value:'inset'},
        { name:'3D outset 边框',value:'outset'},
        { name:'无边框',value:'none'}
    ]

    constructor(
        injector: Injector) {
        super(injector);

        this.data = LayoutStyles.fromJs({});
    }

    set editData(data: LayoutStyles) {
        this.data = LayoutStyles.fromJs(JSON.parse(JSON.stringify(data)));

        this.PaddingMoreOptions = false;
        this.MarginMoreOptions = false;
        this.BorderMoreOptions = false;
        this.BorderRadiusMoreOptions = false;
    }
    
    PaddingAllSides(){
        if(this.PaddingMoreOptions){
            this.data.padding.left = this.data.padding.top;
            this.data.padding.right = this.data.padding.top;
            this.data.padding.bottom = this.data.padding.top;
        }
    }

    MarginAllSides(){
        if(this.MarginMoreOptions){
            this.data.margin.left = this.data.margin.top;
            this.data.margin.right = this.data.margin.top;
            this.data.margin.bottom = this.data.margin.top;
        }
    }

    BorderAllSides(){
        if(!this.BorderMoreOptions){
            this.data.border.left = this.data.border.top;
            this.data.border.right = this.data.border.top;
            this.data.border.bottom = this.data.border.top;
        }
    }

    BorderRadiusAllSides(){
        if(!this.BorderRadiusMoreOptions){
            this.data.borderRadius.topRight = this.data.borderRadius.topLeft;
            this.data.borderRadius.bottomLeft = this.data.borderRadius.topLeft;
            this.data.borderRadius.bottomRight = this.data.borderRadius.topLeft;
        }
    }

    textAlign(val){
        this.data.textAlign.value = val;
    }

    beforeSave(){
        this.PaddingAllSides();
        this.MarginAllSides();
        this.BorderAllSides();
        this.BorderRadiusAllSides();
    }

}
